<?php
namespace User\Model;

use Common\Model\CommonModel;

class SmsLogModel extends CommonModel{
    protected $connection = 'DB_CONFIG2';
    protected $trueTableName = 'sms_log';

    public function sms_cry($user_id,$content){
        header("Content-type: text/html; charset=utf-8");
        if(empty($user_id) || !is_numeric($user_id)){
            return false;
        }
        $user=M( "user", 'system_', C( 'DB_CONFIG2' ) )->field('mobile')->where(['id'=>$user_id])->find();
        $data=array(
            'type'=>3,//初审短信
            'mobile'=>$user['mobile'],
        );
        $this->add($data);
        $dt=$this->cry_send($user['mobile'],$content);
        return $dt;
    }
    public function send($mobile,$content){
        $url='http://112.74.36.247/smsJson.aspx';
        $post_data=array(
            'userid'=>'',
            'account'=>'szyx111704',
            'password'=>strtoupper(md5('szyx111703')),
            //'password'=>'spa4913',
            'mobile'=>$mobile,
            'content'=>$content,
            'sendTime'=>'',
            'action'=>'send',
            'extno'=>'',
        );
        $data=A( 'indexlinks' )->http_post( $url, $post_data);
        if($data['returnstatus']=="Success"){
            return true;
        }else{
            return false;
        }
    }
    public function yx_send($mobile,$content){
        $url='http://112.74.36.247/smsJson.aspx';
        $post_data=array(
            'userid'=>'',
            'account'=>'szyx111704',
            'password'=>strtoupper(md5('szyx111703')),
            //'password'=>'spa4913',
            'mobile'=>$mobile,
            'content'=>$content,
            'sendTime'=>'',
            'action'=>'send',
            'extno'=>'',
        );
        $data=A( 'indexlinks' )->http_post( $url, $post_data );
        //print_r($post_data);exit;
        if($data['returnstatus']=="Success"){
            return true;
        }else{
            return false;
        }
    }
    /*
     * 创瑞云
     */
    public function cry_send($mobile,$content){
        $url='http://api.1cloudsp.com/api/v2/send';
        $AccessKey='FqysKNd0VNWpc12K';
        $AccessSecret='sB4idCiEFeMvHYgZCzRcbZPPvmwebjlX';
        $post_data=array(
            'accesskey'=>$AccessKey,
            'secret'=>$AccessSecret,
            'sign'=>'2117',
            //'templateId'=>$content,
            'mobile'=>$mobile,
            //'content'=>$content
        );
        if(is_numeric($content)){
            $post_data['templateId']=$content;
        }else{
            $post_data['content']=$content;
        }
        $data=A( 'indexlinks' )->http_post( $url, $post_data );
        if($data['msg']=="SUCCESS"){
            return true;
        }else{
            return false;
        }
    }
}